/*
 *  Copyright 2012 Dirk Vranckaert
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package eu.vranckaert.vvl.model;

import android.test.AndroidTestCase;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.Calendar;
import java.util.Date;

/**
 * User: DIRK VRANCKAERT
 * Date: 23/02/12
 * Time: 8:16
 */
public class TrafficInfoTextTest extends AndroidTestCase {
    public void testModel() throws URISyntaxException {
        TrafficInfoTextEnum.InformationType infoType = TrafficInfoTextEnum.InformationType.ACCIDENTS;
        String title = "Accident at E40 Brussels-Coast, direction Brussels, at Ghent. One line blocked!";
        Calendar publicationCalendar = Calendar.getInstance();
        publicationCalendar.set(2011, 12, 6, 16, 32, 9);
        Date publicationDate = publicationCalendar.getTime();

        TrafficInfoText model = new TrafficInfoText(infoType, title, publicationDate);

        assertNotNull(model);
        assertNotNull(model.getInformationType());
        assertEquals(infoType, model.getInformationType());
        assertNotNull(model.getTitle());
        assertEquals(title, model.getTitle());
        assertNotNull(model.getPublicationDate());
        assertEquals(publicationDate, model.getPublicationDate());
        assertNotNull(model.getDescription());
        assertEquals(title, model.getDescription());
        assertNull(model.getLink());

        infoType = TrafficInfoTextEnum.InformationType.TRAFFIC_INFO;
        title = "Due to an accident on the E40 Brussels-Coast, direction Brussels, at Ghent you can experience a delay of 40 minutes";
        publicationCalendar.set(2012, 02, 23, 8, 24, 52);
        publicationDate = publicationCalendar.getTime();
        String description = "This is a dummy description of the accident!";
        URI link = new URI("http://google.com");

        model.setInformationType(infoType);
        model.setTitle(title);
        model.setPublicationDate(publicationDate);
        model.setDescription(description);
        model.setLink(link);

        assertNotNull(model);
        assertNotNull(model.getInformationType());
        assertEquals(infoType, model.getInformationType());
        assertNotNull(model.getTitle());
        assertEquals(title, model.getTitle());
        assertNotNull(model.getPublicationDate());
        assertEquals(publicationDate, model.getPublicationDate());
        assertNotNull(model.getDescription());
        assertEquals(description, model.getDescription());
        assertNotNull(model.getLink());
        assertEquals(link, model.getLink());
    }

    public void testNotEquals() {
        TrafficInfoTextEnum.InformationType infoType = TrafficInfoTextEnum.InformationType.ACCIDENTS;
        String title = "Accident at E40 Brussels-Coast, direction Brussels, at Ghent. One line blocked!";
        Calendar publicationCalendar = Calendar.getInstance();
        publicationCalendar.set(2011, 12, 6, 16, 32, 9);
        Date publicationDate = publicationCalendar.getTime();

        TrafficInfoText model1 = new TrafficInfoText(infoType, title, publicationDate);

        Object o = new Object();
        assertFalse("The model should not be equal to an object", model1.equals(o));

        TrafficInfoText model2 = new TrafficInfoText(infoType, title, publicationDate);

        model2.setInformationType(TrafficInfoTextEnum.InformationType.TRAFFIC_JAMS);
        assertFalse("The two model should not be equal!", model1.equals(model2));

        Calendar publicationCalendar2 = Calendar.getInstance();
        publicationCalendar.set(2009, 1, 1, 0, 0, 0);
        Date publicationDate2 = publicationCalendar2.getTime();
        model2.setPublicationDate(publicationDate2);
        assertFalse("The two model should not be equal!", model1.equals(model2));

        model2.setTitle("Custom Title!");
        assertFalse("The two model should not be equal!", model1.equals(model2));
    }

    public void testEquals() {
        TrafficInfoTextEnum.InformationType infoType = TrafficInfoTextEnum.InformationType.ACCIDENTS;
        String title = "Accident at E40 Brussels-Coast, direction Brussels, at Ghent. One line blocked!";
        Calendar publicationCalendar = Calendar.getInstance();
        publicationCalendar.set(2011, 12, 6, 16, 32, 9);
        Date publicationDate = publicationCalendar.getTime();
        String description1 = "This is a dummy description!";
        String description2 = "This is a another dummy description!";

        TrafficInfoText model1 = new TrafficInfoText(infoType, title, publicationDate);
        model1.setDescription(description1);

        TrafficInfoText model2 = new TrafficInfoText(infoType, title, publicationDate);
        model2.setDescription(description2);
        assertTrue("The two model should be equal!", model1.equals(model2));


    }
    
    public void testHashCode() {
        TrafficInfoTextEnum.InformationType infoType = TrafficInfoTextEnum.InformationType.ACCIDENTS;
        String title = "Accident at E40 Brussels-Coast, direction Brussels, at Ghent. One line blocked!";
        Calendar publicationCalendar = Calendar.getInstance();
        publicationCalendar.set(2011, 12, 6, 16, 32, 9);
        Date publicationDate = publicationCalendar.getTime();
        String description = "This is a dummy description!";

        TrafficInfoText model1 = new TrafficInfoText(infoType, title, publicationDate);
        model1.setDescription(description);
        int hashCodeModel1 = model1.hashCode();

        TrafficInfoText model2 = new TrafficInfoText(infoType, title, publicationDate);
        model2.setDescription(description);
        int hashCodeModel2 = model1.hashCode();

        assertEquals("Both hash codes should be equal!", hashCodeModel1, hashCodeModel2);
    }
}
